// Copyright (c) 2009 Luca Marrocco.
// Modified or written by Luca Marrocco for inclusion with codej.
// Licensed under the Apache License, Version 2.0 (the "License")
package codej.fit.fixtures;

import static codej.gen.Generators.*;
import codej.ast.*;
import codej.ast.*;
import codej.ast.*;
import codej.language.java.*;
import fit.*;

/** @author Luca Marrocco */
public class RecognizeFixture extends ColumnFixture {

	private String recognized;
	public String source;

	private String clean(String generated) {
		return generated.replaceAll("\n", "").replaceAll("  ", " ").trim();
	}

	public boolean isBlock() {
		Node node = Recognize.recognizeBlock(source);
		recognized = clean(generated(java((Block) node)));
		return node instanceof Block;
	}

	public boolean isClassBodyDeclaration() {
		Node node = Recognize.recognizeClassBodyDeclaration(source);
		recognized = clean(generated(java((BodyDeclaration) node)));
		return true;
	}

	public boolean isCompilationUnit() {
		Node node = Recognize.recognizeCompilationUnit(source);
		if (!(node instanceof CompilationUnit))
			return false;
		recognized = clean(generated(java((CompilationUnit) node)));
		return true;
	}

	public boolean isExpression() {
		Node node = Recognize.recognizeExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isLiteral() {
		Node node = Recognize.recognizeLiteral(source);
		recognized = clean(generated(java((Literal) node)));
		return node instanceof Literal;
	}

	public boolean isPrimary() {
		Node node = Recognize.recognizePrimary(source);
		recognized = clean(generated(java((Primary) node)));
		return node instanceof Primary;
	}

	public boolean isStatement() {
		Node node = Recognize.recognizeStatement(source);
		if (!(node instanceof Statement))
			return false;
		recognized = clean(generated(java((Statement) node)));
		return true;
	}

	public boolean isType() {
		Node node = Recognize.recognizeType(source);
		if (!(node instanceof TypeDeclaration))
			return false;
		recognized = clean(generated(java((TypeDeclaration) node)));
		return true;
	}

	public String recognized() {
		return recognized;
	}

	public boolean isUnaryExpression() {
		Node node = Recognize.recognizeUnaryExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isMultiplicativeExpression() {
		Node node = Recognize.recognizeMultiplicativeExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isAdditiveExpression() {
		Node node = Recognize.recognizeAdditiveExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isRelationalExpression() {
		Node node = Recognize.recognizeRelationalExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isInstanceOfExpression() {
		Node node = Recognize.recognizeInstanceOfExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isShiftExpression() {
		Node node = Recognize.recognizeShiftExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isEqualityExpression() {
		Node node = Recognize.recognizeEqualityExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isAndExpression() {
		Node node = Recognize.recognizeAndExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isExclusiveOrExpression() {
		Node node = Recognize.recognizeExclusiveOrExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isInclusiveOrExpression() {
		Node node = Recognize.recognizeInclusiveOrExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isConditionalAndExpression() {
		Node node = Recognize.recognizeConditionalAndExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isConditionalOrExpression() {
		Node node = Recognize.recognizeConditionalOrExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isConditionalExpression() {
		Node node = Recognize.recognizeConditionalExpression(source);
		recognized = clean(generated(java((Expression) node)));
		return node instanceof Expression;
	}

	public boolean isMethodDeclaration() {
		Node node = Recognize.recognizeMethodDeclaration(source);
		recognized = clean(generated(java((MethodDeclaration) node)));
		return node instanceof MethodDeclaration;
	}

	public boolean isMemberDeclaration() {
		Node node = Recognize.recognizeMemberDeclaration(source);
		recognized = clean(generated(java((BodyDeclaration) node)));
		return node instanceof BodyDeclaration;
	}
}